package com.decent.ejfadmin.equity.cardproduct.service.impl;

import com.decent.ejfadmin.common.bean.Page;
import com.decent.ejfadmin.equity.cardproduct.dao.CardProductDao;
import com.decent.ejfadmin.equity.cardproduct.service.CardProductService;
import com.decent.ejfadmin.equity.common.CardOperator;
import com.decent.ejfadmin.equity.common.CardType;
import com.decent.ejfadmin.tools.Base64;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author weicx
 * @date 2019/03/16
 */
@Slf4j
@Service
public class CardProductServiceImpl implements CardProductService {
    @Autowired
    private CardProductDao cardProductDao;

    /**
     * 查询全部卡种
     *
     * @return
     */
    @Override
    public List<CardOperator> queryAllCardOperatorList() {
        return cardProductDao.queryAllCardOperatorList();
    }

    /**
     * 查询权益卡种
     *
     * @param page
     * @param cardOperator
     * @return
     */
    @Override
    public Page<CardOperator> queryCardOperatorPage(Page page, CardOperator cardOperator) {
        int total = cardProductDao.queryCardOperatorCount(cardOperator);
        page.setTotal(total);
        if (total == 0) {
            page.setResultList(new ArrayList<>());
        } else {
            List<CardOperator> cardOperators = cardProductDao.queryCardOperatorList(page, cardOperator);
            for (CardOperator cardOperatorVO : cardOperators) {
                if (cardOperatorVO.getLogoColours() != null) {
                    cardOperatorVO.setLogoColoursBase64(new String(Base64.encodeBase64(cardOperatorVO.getLogoColours())));
                }
                if (cardOperatorVO.getLogo() != null) {
                    cardOperatorVO.setLogoBase64(new String(Base64.encodeBase64(cardOperatorVO.getLogo())));
                }
            }
            page.setResultList(cardOperators);
        }
        return page;
    }

    /**
     * 查询全部卡类型
     *
     * @return
     */
    @Override
    public List<CardType> queryAllCardTypeList() {
        return cardProductDao.queryAllCardTypeList();
    }

}
